//
// Created by root on 2/23/18.
//

#include <string.h>
#include "fpengine.h"
#include "../trans/matcher.h"
#include "../base/utils.h"

String extract(Statement *s) {
    return extract_content(s);
}

String arglist(Statement *s) {
    Queue *queue = transform_queue(s->children, extract_content);
    String string = join_from_queue(queue, " ");
    return string;
}

String target(Statement *s) {
    Queue *filteredQueue = filter_queue(s->children, is_arg);
    Queue *queue = transform_queue(filteredQueue, to_string_statement);
    String string = join_from_queue(queue, " ");
    return string;
}

String funcname(Statement *s) {
    Queue *statements = s->children;
    if (equal_sym(statements->head->element, "(")) {
        Statement *functionName = (Statement *)(statements->head->next->element);
        if (is_sym(functionName)) {
            return functionName->symbol;
        }
    } else {
        String functionNameWithParen = ((Statement *)statements->head->element)->symbol;
        String name = strdup(functionNameWithParen);
        name++;
        return name;
    }
    return NULL;
}

String match(Statement *s) {
    return match_internal(s);
}
